﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyCompanyName.AbpZeroTemplate.Prm
{
    public class DateHelper
    {

        public static int GetWeek(DateTime time)
        {
            GregorianCalendar gc = new GregorianCalendar();
            //得到指定日期是当年第几周
            int weekOfYear = gc.GetWeekOfYear(time, CalendarWeekRule.FirstFullWeek, DayOfWeek.Monday);
            return weekOfYear;
        }

        /// <summary>
        /// 得到星期一的日期
        /// </summary>
        /// <param name="someDate"></param>
        /// <returns></returns>
        public static DateTime GetMondayDate(DateTime someDate)
        {
            int i = someDate.DayOfWeek - DayOfWeek.Monday;
            if (i == -1) i = 6;
            TimeSpan ts = new TimeSpan(i, 0, 0, 0);
            return someDate.Subtract(ts).Date;
        }

        /// <summary>
        /// 得到星期天的日期
        /// </summary>
        /// <param name="someDate"></param>
        /// <returns></returns>
        public static DateTime GetSundayDate(DateTime someDate)
        {
            int i = someDate.DayOfWeek - DayOfWeek.Sunday;
            if (i != 0) i = 7 - i;
            TimeSpan ts = new TimeSpan(i, 0, 0, 0);
            return someDate.Add(ts);
        }
    }
}
